﻿namespace Crux.Core.SQL.Formatter.Core;
/// <summary>
/// 
/// </summary>
public class FormatConfig
{
    /// <summary>
    /// 
    /// </summary>
    public static readonly string DefaultIndent = "  ";
    /// <summary>
    /// 
    /// </summary>
    public static readonly int DefaultColumnMaxLength = 50;
    /// <summary>
    /// 
    /// </summary>
    public readonly string indent;
    /// <summary>
    /// 
    /// </summary>
    public readonly int maxColumnLength;
    /// <summary>
    /// 
    /// </summary>
    public readonly Params parameters;
    /// <summary>
    /// 
    /// </summary>
    public readonly bool uppercase;
    /// <summary>
    /// 
    /// </summary>
    public readonly int linesBetweenQueries;
    /// <summary>
    /// 
    /// </summary>
    public readonly bool skipWhitespaceNearBlockParentheses;
    /// <summary>
    /// 
    /// </summary>
    /// <param name="indent"></param>
    /// <param name="maxColumnLength"></param>
    /// <param name="parameters"></param>
    /// <param name="uppercase"></param>
    /// <param name="linesBetweenQueries"></param>
    /// <param name="skipWhitespaceNearBlockParentheses"></param>
    public FormatConfig(
        string indent,
        int maxColumnLength,
        Params? parameters,
        bool uppercase,
        int linesBetweenQueries,
        bool skipWhitespaceNearBlockParentheses)
    {
        this.indent = indent;
        this.maxColumnLength = maxColumnLength;
        this.parameters = parameters is null ? Params.Empty : parameters;
        this.uppercase = uppercase;
        this.linesBetweenQueries = linesBetweenQueries;
        this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public static FormatConfigBuilder Builder()
    {
        return new FormatConfigBuilder();
    }
    /// <summary>
    /// 
    /// </summary> <summary>
    /// 
    /// </summary>
    public class FormatConfigBuilder
    {
        private string indent = DefaultIndent;
        private int maxColumnLength = DefaultColumnMaxLength;
        private Params? parameters;
        private bool uppercase;
        private int linesBetweenQueries;
        private bool skipWhitespaceNearBlockParentheses;
        /// <summary>
        /// 
        /// </summary>
        public FormatConfigBuilder()
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="indent"></param>
        /// <returns></returns>
        public FormatConfigBuilder Indent(string indent)
        {
            this.indent = indent;
            return this;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="maxColumnLength"></param>
        /// <returns></returns>
        public FormatConfigBuilder MaxColumnLength(int maxColumnLength)
        {
            this.maxColumnLength = maxColumnLength;
            return this;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public FormatConfigBuilder Params(Params parameters)
        {
            this.parameters = parameters;
            return this;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameters"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>    
        public FormatConfigBuilder Params<T>(Dictionary<string, T> parameters)
        {
            return Params(Core.Params.Of(parameters));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public FormatConfigBuilder Params<T>(List<T> parameters)
        {
            return Params(Core.Params.Of(parameters));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uppercase"></param>
        /// <returns></returns>
        public FormatConfigBuilder Uppercase(bool uppercase)
        {
            this.uppercase = uppercase;
            return this;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="linesBetweenQueries"></param>
        /// <returns></returns>
        public FormatConfigBuilder LinesBetweenQueries(int linesBetweenQueries)
        {
            this.linesBetweenQueries = linesBetweenQueries;
            return this;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="skipWhitespaceNearBlockParentheses"></param>
        /// <returns></returns>
        public FormatConfigBuilder SkipWhitespaceNearBlockParentheses(bool skipWhitespaceNearBlockParentheses)
        {
            this.skipWhitespaceNearBlockParentheses = skipWhitespaceNearBlockParentheses;
            return this;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public FormatConfig Build()
        {
            return new FormatConfig(
                indent,
                maxColumnLength,
                parameters,
                uppercase,
                linesBetweenQueries,
                skipWhitespaceNearBlockParentheses);
        }
    }
}